function SDX_RowView(_ID, _Data, _RootObject)
{
 this.RootObject = _RootObject ;
 this.ID=_ID ;
 this.HTMLID = "SDXRow_" + this.RootObject.Name + "_" + _ID ;
 this.SelectionTDHTMLID =  "SDXRow_SelectionTD_" + this.RootObject.Name + "_" + _ID ;
 this.Data = _Data
 this.Cells = new SDX_Cells(this.RootObject, this);
 this.Cells.Initialize() ;
 this.GetEvalObjectString = GetEvalObjectString ;
 this.Selected=false;
 this.SelectRow=SelectRow;
 this.ChangeSelectionStatus = ChangeSelectionStatus ;
 this.ChangeCellsClass = ChangeCellsClass ;
 this.CellClass=""
 this.Delete=Delete
 this.Hide=Hide
 this.Initialize = Initialize ;
 this.HTMLOutPut=HTMLOutPut
 function GetEvalObjectString()
 {
  return this.RootObject.Name + ".Rows.Rows[" + this.RootObject.GetRowMainArrayIndex(this.ID) + "]" ;
 }
 function ChangeCellsClass(_Class)
 {
  var columns = this.RootObject.Columns.GetVisibleColumns() ;
  for(var nX in columns)
  {
    var cell = this.Cells.GetCell(columns[nX].Key) ;
    if(_Class==null)
    {    
       this.RootObject.Styles.RemoveFonts(document.getElementById(cell.HTMLID).style)
    }
    else
    {
       this.RootObject.Styles.SetFont(document.getElementById(cell.HTMLID).style,this.RootObject.Styles.SelectedItemStyle)
    }
  }
 }
 function SelectRow()
 {
  if(this.RootObject.Rows.EditedCell!=null)
   this.RootObject.Rows.EditedCell.NormalMode()
  if(this.RootObject.Rows.SelectedCell!=null)
   this.RootObject.Rows.SelectedCell.NormalMode()
  this.RootObject.GroupByDrager.ClearGroupBy()
  if(SDXCtrlSelect==false)
   this.RootObject.Rows.ClearSelectedRows();
  
  for(var nX=this.RootObject.Rows.SelectedRows.length-1;nX>-1;nX--)
  {
   if(this.RootObject.Rows.SelectedRows[nX].ID == this.ID)
   {
       if(document.getElementById(this.RootObject.Rows.SelectedRows[nX].HTMLID))
       {
          this.RootObject.Rows.SelectedRows[nX].ChangeCellsClass(null) ;
          this.RootObject.Rows.SelectedRows[nX].ChangeSelectionStatus(0) ;
       }
       this.RootObject.Rows.SelectedRows.splice(nX,1);
       return;
   }
  }

  this.ChangeSelectionStatus(1)
  this.Selected=true;
  this.ChangeCellsClass("SelectedRow") ;
  this.RootObject.Rows.SelectedRows[this.RootObject.Rows.SelectedRows.length]=this;
  if(this.RootObject.AllowEditTemplate == true && SDXCtrlSelect==false)
   this.RootObject.Rows.ShowEditTemplate(this);
 }
 function ChangeSelectionStatus(_Status)
 {
  switch(_Status)
  {
   case 0: // EMPTY
   document.getElementById(this.SelectionTDHTMLID).innerHTML = "&nbsp;"
   break ;
   case 1: // SELECT
   document.getElementById(this.SelectionTDHTMLID).innerHTML = "<img height=15 width=15 src=" + this.RootObject.ResourcePath + "images/RowSelectionSelect.gif>"
   break ;
   case 2: // NEW ROW
   document.getElementById(this.SelectionTDHTMLID).innerHTML = "*"
   break ;
   case 3: // EDIT ROW
   document.getElementById(this.SelectionTDHTMLID).innerHTML = "<img  height=15 width=15 src=" + this.RootObject.ResourcePath + "images/RowSelectionEdit.gif>"
   break ;
  }
 }
 function Delete()
 {
  this.RootObject.Rows.Rows[this.RootObject.GetRowMainArrayIndex(this.ID)].IsDeleted = true ;
  var deletedData = this.RootObject.Datas.InsertDeletedData(this.Data.KeyID) ;
  this.Hide();

  if(this.DataTable == null)
    return ;
  for(var nX in this.DataTable.Navigator.FilteredRows)
  {
   if(this.DataTable.Navigator.FilteredRows[nX].Data.KeyID == this.Data.KeyID)
   {
    this.DataTable.Navigator.FilteredRows.splice(nX,1);
   }
  }

  for(var nX in this.DataTable.Rows)
  {
   if(this.DataTable.Rows[nX].Data.KeyID == this.Data.KeyID)
   {
    this.DataTable.Rows.splice(nX,1);
   }
  }
 }
 function Hide()
 {
  document.getElementById(this.HTMLID).style.display='none';
 }
 function Initialize()
 {
 }
 function HTMLOutPut(_display)
 {
  var style = null ;
  if(this.RootObject.AlternateRowTurn == true)
  {
   this.RootObject.AlternateRowTurn = false ;
   style = this.RootObject.Styles.AlternatingItemStyle ;
  }
  else
  {
   this.RootObject.AlternateRowTurn = true ;
   style = this.RootObject.Styles.ItemStyle ;
  }
  var html = "<tr " + this.RootObject.Styles.GetStyleHTML(style) + " id=\"" + this.HTMLID + "\" " + (_display!=null?"style='display:" + _display + "'":"") + " object='" + this.GetEvalObjectString() + "'>"
  var groupBy = this.RootObject.Rows.Rows[this.RootObject.GetRowMainArrayIndex(this.ID)].DataTable.GroupBy;
  var groupByColSpan = (groupBy==null?0:groupBy.Level);
  html += "<td colspan='" + (groupByColSpan) + "' width=10 id=\"" + this.SelectionTDHTMLID + "\" onclick=\"" + this.RootObject.Name + ".Rows.Rows[" + this.ID + "].GetRowView().SelectRow()\" onmouseover=\"this.style.cursor='cursor'\"  " + this.RootObject.Styles.GetStyleHTML(this.RootObject.Styles.SelectorItemStyle) + " >&nbsp</td>";
  var columns = this.RootObject.Columns.GetVisibleColumns() ;
  for(var nX in columns)
  {
   var cell = this.Cells.GetCell(columns[nX].Key) ;
   html +=  "<td id=\"" + cell.HTMLID + "\"" +
            " onclick=\"" + cell.GetEvalObjectString() + ".OnClick()\"" +
            ">" +
            this.Cells.GetCell(columns[nX].Key).HTMLOutPut() +
            "</td>"
  }
  html += "</tr>";
  return html;
 }
}

